import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import classification_report
from sklearn.preprocessing import OneHotEncoder,MinMaxScaler
np.set_printoptions(suppress=True)

pd.set_option('display.max_columns', None)  # 显示所有列
pd.set_option('future.no_silent_downcasting', True)
FEAT_COLS_DESCRIBE = ['乘客性别', '乘客类型','乘客年龄','乘客出行目的','客舱等级',
                      '航程距离','机上Wifi服务满意度',
                      "起飞/降落舒适度满意度",'在线预定满意度',
                      "登机门位置满意度",'机上食物满意度','在线值机满意度','座椅舒适度满意度',
                      "机上娱乐设施满意度"]
FEAT_COLS = ['id', 'Gender', 'Customer Type', 'Age', 'Type of Travel', 'Class',
       'Flight Distance', 'Inflight wifi service',
       'Departure/Arrival time convenient', 'Ease of Online booking',
       'Gate location', 'Food and drink', 'Online boarding', 'Seat comfort',
       'Inflight entertainment', 'On-board service', 'Leg room service',
       'Baggage handling', 'Checkin service', 'Inflight service',
       'Cleanliness', 'Departure Delay in Minutes', 'Arrival Delay in Minutes',
       'satisfaction']
FEAT_COLS_NUMBERS = ['Age','Flight Distance', 'Inflight wifi service',
       'Departure/Arrival time convenient', 'Ease of Online booking',
       'Gate location', 'Food and drink', 'Online boarding', 'Seat comfort',
       'Inflight entertainment', 'On-board service', 'Leg room service',
       'Baggage handling', 'Checkin service', 'Inflight service',
       'Cleanliness', 'Departure Delay in Minutes', 'Arrival Delay in Minutes']
"""
satisfied 满意  
neutral or dissatisfied  中立或不满意
"""

TARGET = ['satisfaction']

df = pd.read_csv('train.csv')
df['satisfaction'] = df['satisfaction'].replace(['neutral or dissatisfied','satisfied'],[0,1])
df = df.iloc[:,1:]
# 数据处理 去除nan
df = df.dropna()

X_train = df[FEAT_COLS_NUMBERS].values
y_train = df['satisfaction'].values.astype(int)

df_test = pd.read_csv('test.csv')
df_test['satisfaction'] = df_test['satisfaction'].replace(['neutral or dissatisfied','satisfied'],[0,1])
df_test = df_test.iloc[:,1:]
# 数据处理 去除nan
df_test = df_test.dropna()
X_test = df_test[FEAT_COLS_NUMBERS].values
y_test = df_test['satisfaction'].values.astype(int)
print( df_test['satisfaction'].unique())
# scaler = MinMaxScaler()
# X_train = scaler.fit_transform(X_train)
# X_test = scaler.transform(X_test)

# <class 'numpy.ndarray'> <class 'numpy.ndarray'>
print(type(X_train),type(y_train))
print(X_train)
print(y_train)
model = DecisionTreeClassifier()
model.fit(X_train,y_train)
# print("w:", model.coef_)
# print("b:", model.intercept_)




r2_score = model.score(X_test,y_test)
print(f"评分:{r2_score}") # 评分:0.9244583478160121
# print(X_test.shape,y_test.shape)
print(classification_report(y_test, model.predict(X_test)))




